package com.ss.android.article.base.feature.detail.presenter;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.account.Spipe;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.action.a.a.Comment;
import com.ss.android.action.a.c.ShareDialog;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.detail.view.DetailCommentDialog;
import com.ss.android.article.base.feature.detail2.cc;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.user.social.ReportActivity;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.model.AbsArticle;
import com.ss.android.model.ItemType;

public final class DetailHelper {
    final Activity mActivity;
    final Handler mHandler;
    private final SimpleArticle h;
    Spipe mSpipe;
    String mWhere;
    ArticleActionHelper mArticleActionHelper;
    View mNotifyView;
    TextView mNotifyViewText;
    private AppData mAppData;
    private ItemType mItemType;
    private String mReportText;
    private View mNotifyViewDivider;
    private TextView mNotifyViewCancel;
    private DetailCommentDialog mDetailCommentDialog;

    public DetailHelper(Activity activity, ItemType itemType, Handler handler, ArticleActionHelper articleActionHelper, String where) {
        this.mActivity = activity;
        this.mItemType = itemType;
        this.mHandler = handler;
        this.mArticleActionHelper = articleActionHelper;
        this.mAppData = AppData.getInstance();
        this.mSpipe = Spipe.inst();
        this.mWhere = where;
        this.h = (this.mActivity instanceof SimpleArticle) ? (SimpleArticle) this.mActivity : null;
        if (this.mItemType == ItemType.ARTICLE) {
            this.mReportText = this.mAppData.detailReportText;
        } else if (this.mItemType == ItemType.ESSAY) {
            this.mReportText = this.mAppData.essayReportText;
        }
        android.support.design.a.isTextEmpty(this.mReportText);
    }

    private void a(int arg2, int arg3) {
        if (!android.support.design.a.t(this.mActivity)) {
            android.support.design.a.showImageToast(this.mActivity, arg3, arg2);
        }
    }

    public final void a() {
        this.mDetailCommentDialog = new DetailCommentDialog(mActivity);
        if (this.mDetailCommentDialog != null && ((mActivity instanceof ShareDialog.b$a))) {
            this.mDetailCommentDialog.g = (ShareDialog.b$a) mActivity;
        }

        this.mNotifyView = mActivity.findViewById(com.ss.android.article.browser.R.id.notify_view);
        this.mNotifyViewDivider = mActivity.findViewById(com.ss.android.article.browser.R.id.notify_view_divider);
        this.mNotifyViewText = mActivity.findViewById(com.ss.android.article.browser.R.id.notify_view_text);
        this.mNotifyViewCancel = mActivity.findViewById(com.ss.android.article.browser.R.id.notify_view_cancel);
        mActivity.findViewById(com.ss.android.article.browser.R.id.notify_view_cancel_layout);
        if (this.mNotifyViewCancel != null) {
            this.mNotifyViewCancel.setOnClickListener(new View.OnClickListener() {

                public final void onClick(View arg11) {
                    AbsArticle absArticle = DetailHelper.this.getAbsArticle();
                    if (absArticle != null) {
                        long v6 = DetailHelper.this.getAdId();
                        int v0 = absArticle.userDislike ? 10 : 9;
                        if (!absArticle.userDislike) {
                            MobClickCombiner.onEvent(DetailHelper.this.mActivity, DetailHelper.this.mWhere, "report_dislike");
                        }

                        absArticle.userDislike = !absArticle.userDislike;
                        DetailHelper.this.mArticleActionHelper.a(v0, absArticle, v6);
                        DetailHelper.this.mHandler.removeMessages(100);
                        if (!absArticle.userDislike) {
                            DetailHelper.this.mNotifyView.setVisibility(View.GONE);
                            return;
                        }
                        DetailHelper.this.mNotifyViewText.setText(DetailHelper.this.mSpipe.isLogin ? R.string.toast_dislike_success : R.string.toast_dislike_success_anonymous);
                        DetailHelper.this.mNotifyView.setVisibility(View.VISIBLE);
                        DetailHelper.this.mHandler.sendEmptyMessageDelayed(100, 5000);
                    }
                }
            });
        }
    }

    public final void a(Comment comment) {
        if (comment != null && this.mActivity != null && !this.mActivity.isFinishing()) {
            this.b("", comment.commentId, false);
            this.mDetailCommentDialog.w = comment;
            this.mDetailCommentDialog.setHint(this.mActivity.getString(com.ss.android.article.browser.R.string.reply_comment_to, new Object[]{comment.userName}));
        }
    }

    public final void a(AbsArticle arg3, long arg4) {
        String v1 = null;
        if (arg3 != null) {
            if (!android.support.design.a.isTextEmpty(v1)) {
                this.mAppData.W = v1;
            }

            if (this.mItemType == ItemType.ESSAY) {
                ReportActivity.a(this.mActivity, arg3, arg4, 2);
                return;
            }

            if (((arg3 instanceof Article)) && !android.support.design.a.isTextEmpty(((Article) arg3).videoId)) {
                ReportActivity.a(this.mActivity, arg3, arg4, 4);
                return;
            }

            ReportActivity.a(this.mActivity, arg3, arg4, 0);
        }
    }

    public final void a(String arg3, long arg4, boolean arg6) {
        if (this.mActivity != null && !this.mActivity.isFinishing()) {
            this.b(arg3, arg4, arg6);
            this.mDetailCommentDialog.w = null;
            String v0 = com.ss.android.action.bb.a().c;
            if (android.support.design.a.isTextEmpty(v0)) {
                v0 = this.mActivity.getString(com.ss.android.article.browser.R.string.reply_post_hint);
            }
            this.mDetailCommentDialog.setHint(v0);
        }
    }

    public final boolean handleMsg(Message message) {
        AppData.isNightMode();
        switch (message.what) {
            case 100:
                if (this.mNotifyView != null) {
                    this.mNotifyView.setVisibility(View.GONE);
                }
                return true;
            case 1034:
                this.a(R.drawable.g7, R.string.toast_report_ok);
                return true;
            case 1035:
                this.a(R.drawable.g6, R.string.toast_report_fail);
               return true;
            default: {
                return false;
            }
        }
    }

    private void b(String arg9, long arg10, boolean arg12) {
        long v2 = this.getAdId();
        AbsArticle v1 = this.getAbsArticle();
        if (v1 != null) {
            if ((this.mActivity instanceof cc)) {
                Activity v0 = this.mActivity;
                int v4 = ((cc) v0).i();
                long v6 = ((cc) v0).j();
                if (v4 >= 0) {
                    this.mDetailCommentDialog.s = v4;
                }

                if (v6 <= -1) {
                } else {
                    this.mDetailCommentDialog.t = v6;
                }
            }
            DetailCommentDialog v4_1 = this.mDetailCommentDialog;
            int v0_1 = arg12 ? 1 : 2;
            v4_1.u = v0_1;
            this.mDetailCommentDialog.a(v1, v2, arg9, arg10);
        }
    }

    public final void b() {
        if (this.mDetailCommentDialog != null) {
            this.mDetailCommentDialog.r = true;
        }
    }

    public final boolean c() {
        long v2 = 0;
        AbsArticle absArticle = this.getAbsArticle();
        if (absArticle == null) {
            return false;
        } else {
            if ((this.mSpipe.isLogin) && !this.mDetailCommentDialog.isShowing()) {
                this.mDetailCommentDialog.a(absArticle, v2, null, v2);
            }
            return true;
        }
    }

    public final void notifyViewAdaptNightMode() {
        Resources resources = this.mActivity.getResources();
        AppData.isNightMode();
        if (this.mNotifyView != null && this.mNotifyViewCancel != null) {
            UIUtils.setBackgroundResource(this.mNotifyView, R.drawable.bk);
            UIUtils.setBackgroundResource(this.mNotifyViewDivider, R.color.notify_view_divider);
            this.mNotifyViewText.setTextColor(resources.getColor(R.color.m2));
            this.mNotifyViewCancel.setTextColor(resources.getColor(R.color.m2));
        }
    }

    final AbsArticle getAbsArticle() {
        return this.h != null ? this.h.getArticle() : null;
    }

    final long getAdId() {
        return this.h != null ? this.h.getArticleId() : 0;
    }

    public interface SimpleArticle {
        AbsArticle getArticle();

        long getArticleId();

        int getCommentMode();
    }
}

